﻿using DialogServiceLibrary.Service;
using FileTrackerWPF.WindowViewModelMapping;
using ServiceLocator;
using ServiceLocator.WindowViewModelMapping;
using System.Threading;
using System.Windows;

namespace FileTrackerWPF
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		protected override void OnStartup(StartupEventArgs argE)
		{
			
			//ConfigurationHandler for accessing config data
			Locator.RegisterSingleton<IConfigurationHandler, ConfigurationHandler>(new ConfigurationHandler(System.AppDomain.CurrentDomain.BaseDirectory));

			//For mapping viewmodles and the windows they open
			Locator.RegisterSingleton<IWindowViewModelMappings, FileTrackerMapping>();

			//DialogService for opening windows in MVVM
			Locator.RegisterSingleton<IDialogService, DialogService>();

			//Resiter the SynchronizationContext so we can marshal back to the UI thread when we need to.
			Locator.RegisterSingleton<SynchronizationContext, SynchronizationContext>(SynchronizationContext.Current);

			//Create the ViewModel
			MainViewModel localViewModel = new MainViewModel();

			MainView localView = new MainView();
			localView.DataContext = localViewModel;
			localView.Show();

			base.OnStartup(argE);
		}
	}
}